import request from '@/config/axios'

/**
 * 能源统计 API
 */

export interface EnergyStatisticsParams {
  deviceId?: string
  timeRange: 'day' | 'week' | 'month' | 'year'
  compareType?: 'day' | 'week' | 'month'
}

export interface EnergyStatisticsVO {
  deviceCount: number // 设备总数
  totalEnergy: number // 设备能耗总数（kWh）
  todayReportCount: number // 今日上报数量
  warningCount: number // 警告数据数量
  dangerCount: number // 危险数据数量
  compareRates: Record<string, number> // 环比变化率
  trendData?: EnergyTrendVO[] // 趋势数据
  compareData?: EnergyCompareVO[] // 环比数据
  distributionData?: EnergyDistributionVO[] // 分布数据
}

export interface EnergyTrendVO {
  time: string
  dataType: string
  value: number
}

export interface EnergyCompareVO {
  dataType: string
  currentValue: number
  previousValue: number
  changeRate: number
}

export interface EnergyDistributionVO {
  name: string
  value: number
}

// 获取能源统计数据
export const getEnergyStatistics = (params: EnergyStatisticsParams) => {
  return request.get<EnergyStatisticsVO>({ url: '/energy/statistics/data', params })
}

// 获取能耗趋势数据
export const getEnergyTrend = (params: EnergyStatisticsParams) => {
  return request.get<EnergyTrendVO[]>({ url: '/energy/statistics/trend', params })
}

// 获取能耗环比数据
export const getEnergyCompare = (params: EnergyStatisticsParams) => {
  return request.get<EnergyCompareVO[]>({ url: '/energy/statistics/compare', params })
}

// 获取能耗分布数据
export const getEnergyDistribution = (params: EnergyStatisticsParams) => {
  return request.get<EnergyDistributionVO[]>({ url: '/energy/statistics/distribution', params })
}
